<template>
  <div class="recommend-box" v-if="list.length">
    <div class="title">推荐</div>
    <div class="news-box">
      <el-row :gutter="20">
        <el-col :span="8" v-for="(item, index) of list" :key="index">
          <div class="news-item" @click="onDetail(item)">
            <div class="news-img">
              <div class="img" :style="{backgroundImage: 'url(' + item.coverUrl + ')'}"></div>
              <div class="play-icon"></div>
            </div>
            <div class="news-title">{{item.name}}</div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import { advertsList } from '@/api/api';
export default {
  data() {
    return {
      list: []
    }
  },
  mounted() {
    this.getList();
  },
  methods: {
    // 获取推荐列表
    async getList() {
      const params = {
        pageType: 'HOME_PAGE',
        type: 'RECOMMEND',
        status: 1
      };
      const res = await advertsList(params);
      this.list = res.list.slice(0, 3);
    },
    // 详情
    onDetail() {
      // this.$router.push({name: 'InformationDetail', query: {id: item.uuid}});
    }
  }
}
</script>

<style lang="scss" scoped>
.recommend-box {
  margin-bottom: 52px;
  .title {
    height: 32px;
    font-size: 24px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #272727;
    line-height: 32px;
    margin-bottom: 24px;
  }
  .news-box {
    .news-item {
      height: 238px;
      cursor: pointer;
      .news-img {
        height: 150px;
        border-radius: 4px 4px 0px 0px;
        position: relative;
        overflow: hidden;
        .img {
          height: 150px;
          background-size: cover;
          transform: scale(1);
          transition: all 1s;
        }
        &:hover {
          .img {
            transform: scale(1.12);
            transition: all 1s;
          }
        }
        .play-icon {
          width: 40px;
          height: 40px;
          position: absolute;
          top: 50%;
          left: 50%;
          margin-top: -20px;
          margin-left: -20px;
          background: url('../../../assets/play-icon.png');
          background-size: cover;
          cursor: pointer;
        }
      }
      .news-title {
        height: 60px;
        padding: 12px 16px 16px;
        background: #F9F9F9;
        border-radius: 0px 0px 4px 4px;
        font-size: 14px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #272727;
        line-height: 20px;
      }
    }
  }
}
</style>